home *** CD-ROM | disk | FTP | other *** search
- /*
- Spinning text
-
- This application will create a line of text, set the text to an hsv color, rotate, and draw
- the text.
-
-
- NOTES:
- • This file requires the following files to run correctly:
- "graphics shell.c", "FontLibrary.c", "GraphicsDebugLibrary.c", "TransformLibrary.c".
-
- • For the best printing results, print this file in "landscape".
-
-
- Change History:
-
- 4/96 bob Updated #includes to support changed GX Library names.
- Changed fixed to Fixed.
- Updated the note regarding the files needed to run.
- Updated the copyright date.
-
- ©1990-1996 Apple Computer, Inc.
- All rights reserved.
- */
-
- #include <Events.h>
- #include <Windows.h>
-
- #include "GraphicsLibraries.h"
- #include <GXEnvironment.h>
- #include "FontLibrary.h"
- #include "graphics shell.h"
-
- #define kNumberOfTextStringsDrawn 19
-
- //
- // Set up the title and size of the window
- //
- Str255 gWindowTitle = "\p Spinning Text ";
- Rect gWindowQDRect = {50, 10, 440, 440};
-
- //
- // If gDebugging = TRUE, graphics library errors and notices will be posted. This functionality will only work with
- // the "debugging" version of the QuickDraw GX init. If this version of the init is not installed, nothing bad will happen,
- // but these functions will not work. The "debugging" version of the QuickDraw GX init is approximately 700K.
- //
- Boolean gDebugging = true;
-
-
- //
- // Set "gGiveMeValidation" to TRUE, if you will receive run-time validation.
- //
- Boolean gGiveMeValidation = true;
-
-
- //
- // gGraphicsHeapSize sets the size of the graphics gxHeap created by calling the GXNewGraphicsClient routine
- // in main () within graphics shell.c. You can determine the amount of graphics gxHeap required by using GraphicsBug.
- // With gGraphicsHeapSize set to 15k, I had 4 free blocks left in the graphics gxHeap. Sounds good to me.
- //
- long gGraphicsHeapSize = 15;
-
- gxShape gTextShape;
- gxColor gTextColor;
- short gTotalNumberOfTextStringsDrawn;
- short gDegreesToRotateText;
- Fixed gShapesXCoordinateCenter,gShapesYCoordinateCenter;
-
-
-
- /*------ DoInitialization ---------------------------------------------------------------------------------*/
-
- void DoInitialization(aWindow)
- WindowPtr aWindow;
- {
- gxPoint textPostion;
- gxRectangle textShapeBounds;
-
- gTotalNumberOfTextStringsDrawn = 0;
- gDegreesToRotateText = 20;
-
- //
- // Set up the starting text postion. This location will be set up when we
- // create our text gxShape.
- //
- textPostion.x = ff(50);
- textPostion.y = ff(200);
-
- //
- // Create the text, and set the gxFont and size.
- //
- gTextShape = GXNewText(13,(unsigned char*)"QuickDraw™ GX", &textPostion);
- SetShapeCommonFont(gTextShape, timesFont);
- GXSetShapeTextSize(gTextShape, ff(45));
-
- //
- // A gxColor, to run through hsv space with...
- //
- gTextColor.space = gxHSVSpace;
- gTextColor.profile = nil;
- gTextColor.element.hsv.hue = 0x2700;
- gTextColor.element.hsv.saturation = 0xFFFF;
- gTextColor.element.hsv.value = 0xFFFF;
-
- //
- // Get the bounds of our text gxShape. We will then determine the center of the gxShape.
- // The center of the gxShape will be used below in GXRotateShape which will enable us to rotate
- // our gxShape around it's center.
- //
- GXGetShapeBounds(gTextShape, 0L, &textShapeBounds);
- gShapesXCoordinateCenter = textShapeBounds.left + textShapeBounds.right >> 1;
- gShapesYCoordinateCenter = textShapeBounds.top + textShapeBounds.bottom >> 1;
-
- GXSetShapeAttributes (gTextShape, gxMapTransformShape);
- }
-
-
-
- /*------ DoDraw ---------------------------------------------------------------------------------------*/
-
- void DoDraw(aWindow)
- WindowPtr aWindow;
- {
- if (gTotalNumberOfTextStringsDrawn == kNumberOfTextStringsDrawn)
- {
- gxMapping textShapeMap;
-
- //
- // The text has been rotated 360 degrees. Let's erase the contents of the window
- // and reset the Shape's Transform. By resetting the Transform will reset the Transform
- // back to the GX default gxTransform (i.e. no rotate).
- //
- // With the call to GXRotateShape below, we have been only effecting the Shape's gxTransform
- // instead of the Shape's geometry because we had set the gxMapTransformShape attribute above.
- //
- SetPort (aWindow);
- EraseRect(&(aWindow)->portRect);
-
- GXGetTransformMapping(GXGetShapeTransform(gTextShape), &textShapeMap);
- ResetMapping(&textShapeMap);
-
- //
- // Reverse the rotation direction
- //
- gDegreesToRotateText = -gDegreesToRotateText;
-
- gTotalNumberOfTextStringsDrawn = 0;
- }
-
- GXSetShapeColor(gTextShape, &gTextColor);
- GXDrawShape (gTextShape);
-
- GXRotateShape(gTextShape, ff(gDegreesToRotateText), gShapesXCoordinateCenter, gShapesYCoordinateCenter);
-
- gTextColor.element.hsv.hue += 0x0900;
-
- gTotalNumberOfTextStringsDrawn++;
- }
-
-
- /*------ DoDispose -------------------------------------------------------------------------------------*/
-
- void DoDispose(aWindow)
- WindowPtr aWindow;
- {
- //
- // You should always dispose of your GX graphics objects before tossing your window. Why? It's generally good
- // form and this approach guarantees that everything is disposed. If you had not disposed of everything, the
- // call to DisposeWindow should dispose of the objects. If you are running the debugging version of the
- // SecretGraphics init with notices set, you will receive a notice that you had not disposed of everything. You
- // can turn notices on in this file by setting gDebugging = TRUE (above).
- //
- GXDisposeShape(gTextShape);
- GXDisposeShape(gWindowBoundsShape);
- DisposeWindow(aWindow);
- }
-
-
-
- /*------ DoClick ---------------------------------------------------------------------------------------*/
-
- void DoClick( orgMouseLoc, theWindow )
- gxPoint orgMouseLoc;
- WindowPtr theWindow;
- {
- }
-
-
- /*------ DoIdle ----------------------------------------------------------------------------------------*/
-
- void DoIdle(aWindow)
- WindowPtr aWindow;
- {
- DoDraw(aWindow);
- }
-